home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: What is &Variable (declared as: char Variable[10])?
- Date: 3 Mar 1996 21:01:32 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hdtfcINN4l3@keats.ugrad.cs.ubc.ca>
- References: <4gqpa1$3h9@alcor.usc.edu> <4gtab6$acb@ceylon.gte.com> <4gvksnINNnug@anvil.ugrad.cs.ubc.ca> <TANMOY.96Feb29100937@qcd.lanl.gov>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <TANMOY.96Feb29100937@qcd.lanl.gov>,
- Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> wrote:
- >In article <4gvksnINNnug@anvil.ugrad.cs.ubc.ca>
- >c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
- >
- ><snip>
- >KK: False. The _name_ 'myarray' is an array object. The _expression_ 'myarray'
- >KK: produces a pointer.
- >
- >except when it is the direct operand of the & operator or the direct
- >operand of the sizeof operator. (You say that later: but that is much
- >later :-).
-
- Well, the operand of a sizeof operator can be an expression, or a parenthesized
- type name. If it is an expression, it is not evaluated, but only checked for
- those attributes which determine the size of the lvalue. Conceptually, the
- expression still has a value, albeit one which is thrown away.
-
- In the case of &, the operator does require the ``cast-expression''
- syntactic unit, but again, it is interested in something other than the
- straightforward value of the expression. The subject must be marked as an
- lvalue that meets certain criteria. For all I know, in the expression
-
- &myarray
-
- where myarray is an array of char, the myrray constituent could still be
- treated as an expression that produces a pointer, a value that is ignored
- because some other attribute of the expression is interesting to the &
- operator.
-
- By the same reasoning, if I have an integer 'i' initialized to 3, and write
-
- &i
-
- the i constituent is still an expression whose value is 3. However, the &
- construct is interested in that i is an lvalue of a certain type and address,
- and that it has an address, and the (conceptually present) computational value
- is ignored.
-
- It's always useful to think of expressions and other constructs as not
- computing only values, but also all kinds of other attributes, including type,
- l- versus r- value markers and so forth, any of which can be the item of
- interest to a dominating syntactic unit in favor of the value.
-
- In saying what the expression 'myarray' is, I should have been more thorough by
- mentioning what other attributes it has, not just the principal computational
- pointer value. Thus, here is my second attempt:
-
- myarray is an expression whose evaluation calls for the generation of a value,
- whose type is pointer to char and which points to the first element of myarray.
- However, the expression myrray also has other attributes. It is an lvalue which
- can be the subject of sizeof() and & operators, which are not interested in
- computing the pointer value, but which look at the type and storage attributes
- of myarray itself. It is not a modifiable lvalue, hence it cannot be assigned
- to.
-
- A compiler could represent this reality in the form of a parse tree, in which
- myarray would form a ``unary expression'' node. After type-checking and other
- phases, the node would contain attribute information which would indicate that
- it is an lvalue, and that it evaluates to a char * pointer type. Of course, the
- code to evaluate will not be created by the code generation phase since the &
- operator does not require the value attribute for anything.
-
- The bottom line is that it's not necessary to view the subjects of & and sizeof
- as special cases; expressions are the same in the context of these operators as
- they are anywhere else, and can be seen as producing the same values.
- --
-
-